package cn.wuqingna.legendgem.api.attribute.imp

import cn.wuqingna.legendgem.api.attribute.AbsAttributeSource
import cn.wuqingna.legendgem.api.attribute.AttributeData
import cn.wuqingna.legendgem.cache.PlayerManager
import cn.wuqingna.legendgem.util.isDouble
import org.bukkit.Bukkit
import java.util.UUID

class SuitSource(
    val uuid: UUID
): AbsAttributeSource() {

    override fun getAttribute(): AttributeData? {
        val cache = PlayerManager.get(uuid)
        val customDate = mutableMapOf<String, Double>()
        val attributes = mutableListOf<String>()
        cache.suit.forEach { (t, u) ->

            attributes += u.attributes

            u.customData.forEach { (key, value) ->
                if (customDate.containsKey(key)) {
                    if (value.isDouble()){
                        customDate[key] = customDate[key]!! + value.toDouble()
                    } else {
                        customDate[key] = customDate[key]!! + 1
                    }
                } else {
                    if (value.isDouble()){
                        customDate[key] = value.toDouble()
                    } else {
                        customDate[key] = 1.0
                    }

                }
            }
        }


        return AttributeData(attributes, customDate)

    }

}